﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using Skynet.BusinessEntities;
using Microsoft.Practices.Unity;

namespace Skynet.BusinessLogic.BusinessComponents
{
    public enum CustomerFindOptions
    {
        GetOne, 
        GetAll,
        GetByUserName
    }
    public enum CustomerSearchOption
    {
        GetAll
 
    }



    [ServiceContract]
    public interface IBCCustomers 
    {
        [OperationContract]
        void MaintenanceCustomers(Customer item);

        [OperationContract]
        void MaintenanceOrganization(Organization item);

        
        

    }
    public class BCCustomers :  IBCCustomers
    {
        [Dependency]
        public DataAccess.ICustomerRepository CustomerRepository { get; set; }

        [Dependency]
        public Skynet.DataAccess.IOrganizationRepository OrganizationRepository { get; set; }

        public void MaintenanceCustomers(Customer item)
        {
            switch (item.ChangeTracker.State)
            {
                case ObjectState.Unchanged:
                    break;
                case ObjectState.Added:
                    this.CustomerRepository.Add(item);
                    break;
                case ObjectState.Modified:
                    this.CustomerRepository.Update(item);
                    break;
                case ObjectState.Deleted:
                    this.CustomerRepository.Delete(item);  
                    break;
                default:
                    break;
            }
            item.AcceptChanges();  
        }

        public void MaintenanceOrganization(Organization item)
        {
            this.OrganizationRepository.Maintenance(item);
        }

    }
}
